package cn.jpms.mending

import org.gradlex.javamodule.moduleinfo.ExtraJavaModuleInfoPluginExtension

/**
 * TomcatEmbedExtra
 *
 * @author 清寒
 */
class TomcatEmbedExtra : ModuleExtraInfo {
    @Suppress("SpellCheckingInspection")
    override fun config(ext: ExtraJavaModuleInfoPluginExtension) {

        ext.module("org.apache.tomcat.embed:tomcat-embed-core", "org.apache.tomcat.embed.core") {
            patchRealModule()

            requires("java.desktop")
            requires("java.instrument")
            requires("java.logging")
            requires("java.rmi")
            requires("jakarta.servlet")
            requiresStatic("jakarta.ejb")
            requiresStatic("jakarta.mail")
            requiresStatic("jakarta.persistence")
            requiresStatic("jakarta.xml.ws")
            requiresStatic("java.xml.ws")
            requiresTransitive("jakarta.annotation")
            requiresTransitive("java.management")
            requiresTransitive("java.naming")
            requiresTransitive("java.security.jgss")
            requiresTransitive("java.sql")
            requiresTransitive("java.xml")

            // removePackage("jakarta.security.auth.message")
            // removePackage("jakarta.security.auth.message.callback")
            // removePackage("jakarta.security.auth.message.config")
            // removePackage("jakarta.security.auth.message.module")
            removePackage("jakarta.servlet")
            removePackage("jakarta.servlet.annotation")
            removePackage("jakarta.servlet.descriptor")
            removePackage("jakarta.servlet.http")
            removePackage("jakarta.servlet.resources")

            exports("org.apache.catalina")
            exports("org.apache.catalina.authenticator")
            exports("org.apache.catalina.authenticator.jaspic")
            exports("org.apache.catalina.connector")
            exports("org.apache.catalina.core")
            exports("org.apache.catalina.deploy")
            exports("org.apache.catalina.filters")
            exports("org.apache.catalina.loader")
            exports("org.apache.catalina.manager")
            exports("org.apache.catalina.manager.host")
            exports("org.apache.catalina.manager.util")
            exports("org.apache.catalina.mapper")
            exports("org.apache.catalina.mbeans")
            exports("org.apache.catalina.realm")
            exports("org.apache.catalina.security")
            exports("org.apache.catalina.servlets")
            exports("org.apache.catalina.session")
            exports("org.apache.catalina.startup")
            exports("org.apache.catalina.users")
            exports("org.apache.catalina.util")
            exports("org.apache.catalina.valves")
            exports("org.apache.catalina.valves.rewrite")
            exports("org.apache.catalina.webresources")
            exports("org.apache.catalina.webresources.war")
            exports("org.apache.coyote")
            exports("org.apache.coyote.ajp")
            exports("org.apache.coyote.http11")
            exports("org.apache.coyote.http11.filters")
            exports("org.apache.coyote.http11.upgrade")
            exports("org.apache.coyote.http2")
            exports("org.apache.juli")
            exports("org.apache.juli.logging")
            exports("org.apache.naming")
            exports("org.apache.naming.factory")
            exports("org.apache.naming.java")
            exports("org.apache.tomcat")
            exports("org.apache.tomcat.jni")
            exports("org.apache.tomcat.util")
            exports("org.apache.tomcat.util.bcel.classfile")
            exports("org.apache.tomcat.util.buf")
            exports("org.apache.tomcat.util.codec.binary")
            exports("org.apache.tomcat.util.collections")
            exports("org.apache.tomcat.util.compat")
            exports("org.apache.tomcat.util.descriptor")
            exports("org.apache.tomcat.util.descriptor.tagplugin")
            exports("org.apache.tomcat.util.descriptor.web")
            exports("org.apache.tomcat.util.digester")
            exports("org.apache.tomcat.util.file")
            exports("org.apache.tomcat.util.http")
            exports("org.apache.tomcat.util.http.fileupload")
            exports("org.apache.tomcat.util.http.fileupload.disk")
            exports("org.apache.tomcat.util.http.fileupload.impl")
            exports("org.apache.tomcat.util.http.fileupload.servlet")
            exports("org.apache.tomcat.util.http.fileupload.util")
            exports("org.apache.tomcat.util.http.parser")
            exports("org.apache.tomcat.util.log")
            exports("org.apache.tomcat.util.modeler")
            exports("org.apache.tomcat.util.modeler.modules")
            exports("org.apache.tomcat.util.net")
            exports("org.apache.tomcat.util.net.openssl")
            exports("org.apache.tomcat.util.net.openssl.ciphers")
            exports("org.apache.tomcat.util.res")
            exports("org.apache.tomcat.util.scan")
            exports("org.apache.tomcat.util.security")
            exports("org.apache.tomcat.util.threads")

            uses("org.apache.juli.logging.Log")
        }
        ext.module("org.apache.tomcat.embed:tomcat-embed-el", "org.apache.tomcat.embed.el") {
            preserveExisting()

            removePackage("jakarta.el")
        }
        ext.module("org.apache.tomcat.embed:tomcat-embed-websocket", "org.apache.tomcat.embed.websocket") {
            preserveExisting()

            removePackage("jakarta.websocket")
            removePackage("jakarta.websocket.server")
        }

    }
}
